Return to start page
Systems/Character/Struct Fight.j
1 /// The fps common.j file is required.
2 /// Do not use this library, it is unfinished!
3 library AStructSystemsCharacterFight requires optional ALibraryCoreDebugMisc, AStructCoreGeneralHashTable, AStructSystemsCharacterAbstractCharacterSystem
4
5 struct AFight extends AAbstractCharacterSystem
6 //static start members
7 private static boolean m_useFps
8 private static string m_order
9 private static real m_time
10 private static string m_hitAnimation
11 private static real m_angle
12 //members
13 private trigger m_fightTrigger
14 private timer m_timer
15 private boolean m_hasOrdered
16 private boolean m_canOrder
17
18 //! runtextmacro optional A_STRUCT_DEBUG("\"AFight\"")
19
20 public method enable takes nothing returns nothing
21 call super.enable()
22 call EnableTrigger(this.m_fightTrigger)
23 if (TimerGetRemaining(this.m_timer) > 0.0) then
24 call PauseTimerBJ(false, this.m_timer)
25 endif
26 endmethod
27
28 public method disable takes nothing returns nothing
29 call super.disable()
30 call DisableTrigger(this.m_fightTrigger)
31 if (TimerGetRemaining(this.m_timer) > 0.0) then
32 call PauseTimerBJ(true, this.m_timer)
33 endif
34 endmethod
35
36 private method hit takes nothing returns nothing
37 set this.m_hasOrdered = false
38 set this.m_canOrder = false
39
40 //call UnitDamagePoint(this.unit(), 0.0, unitPolarProjectionX(this.unit(), (GetUnitFacing(this.unit()) + thistype.angle), AFocus.range)
41
42 set this.m_canOrder = true
43 endmethod
44
45 private static method timerFunctionReset takes nothing returns nothing
46 local timer expiredTimer = GetExpiredTimer()
47 local thistype this = AHashTable.global().handleInteger(expiredTimer, "this")
48 set this.m_hasOrdered = false
49 set expiredTimer = null
50 endmethod
51
52 private method startTimer takes nothing returns nothing
53 set this.m_hasOrdered = true
54 call TimerStart(this.m_timer, thistype.m_time, false, function thistype.timerFunctionReset)
55 call AHashTable.global().setHandleInteger(this.m_timer, "this", this)
56 endmethod
57
58 private static method triggerConditionOrder takes nothing returns boolean
59 return GetIssuedOrderId() == OrderId(thistype.m_order)
60 endmethod
61
62 private static method triggerActionOrder takes nothing returns nothing
63 local trigger triggeringTrigger = GetTriggeringTrigger()
64 local thistype this = AHashTable.global().handleInteger(triggeringTrigger, "this")
65 if (this.m_canOrder) then
66 if (this.m_hasOrdered) then
67 call this.hit()
68 else
69 call this.startTimer()
70 endif
71 endif
72 set triggeringTrigger = null
73 endmethod
74
75 private method createFightTrigger takes nothing returns nothing
76 local event triggerEvent
77 local conditionfunc conditionFunction
78 local triggercondition triggerCondition
79 local triggeraction triggerAction
80 if (not thistype.m_useFps) then
81 set triggerEvent = TriggerRegisterUnitEvent(this.m_fightTrigger, this.unit(), EVENT_UNIT_ISSUED_ORDER)
82 set conditionFunction = Condition(function thistype.triggerConditionOrder)
83 set triggerCondition = TriggerAddCondition(this.m_fightTrigger, conditionFunction)
84 set triggerEvent = null
85 else
86 //call TriggerRegisterMouseEvent(this.m_fightTrigger, EVENT_LMOUSEDOWN)
87 endif
88 set triggerAction = TriggerAddAction(this.m_fightTrigger, function thistype.triggerActionOrder)
89 call AHashTable.global().setHandleInteger(this.m_fightTrigger, "this", this)
90 set conditionFunction = null
91 set triggerCondition = null
92 set triggerAction = null
93 endmethod
94
95 public static method create takes ACharacter character returns thistype
96 local thistype this = thistype.allocate(character)
97 //members
98 set this.m_timer = CreateTimer()
99
100 call this.createFightTrigger()
101 return this
102 endmethod
103
104 private method destroyUsedTimer takes nothing returns nothing
105 call AHashTable.global().destroyTimer(this.m_timer)
106 set this.m_timer = null
107 endmethod
108
109 private method destroyFightTrigger takes nothing returns nothing
110 call AHashTable.global().destroyTrigger(this.m_fightTrigger)
111 set this.m_fightTrigger = null
112 endmethod
113
114 public method onDestroy takes nothing returns nothing
115
116 call this.destroyUsedTimer()
117 call this.destroyFightTrigger()
118 endmethod
119
120 /**
121 * @param useFps false, new implementation, uses the left mouse key
122 * @param order "move"
123 * @param time 0.5
124 * @param hitAnimation "attack"
125 * @param angle 20.0
126 */
127 public static method init takes boolean useFps, string order, real time, string hitAnimation, real angle returns nothing
128 debug if (useFps and not Asl.useRtc()) then
129 debug call thistype.staticPrint("FPS is enabled but RtC isn't.")
130 debug endif
131 //static start members
132 set thistype.m_useFps = useFps
133 set thistype.m_order = order
134 set thistype.m_time = time
135 set thistype.m_hitAnimation = hitAnimation
136 set thistype.m_angle = angle
137 endmethod
138 endstruct
139
140 endlibrary